(function(){
startTestGroup('Libraries - Collections Tests (jclass.collections.Dictionary)');
include("/libraries/jclass/collections.js");

assertNotNull("Namespace jclass.collections exists", jclass.collections);
assertNotNull("Class jclass.collections.Dictionary exists", jclass.collections.Dictionary);

var x = new jclass.collections.Dictionary([1,"text"]);
assertTrue("Dictionary can be constructed with a initial source", x.toJSON() == '[1,"text"]');

var obj1 = {label:"text", text:"a"};
x.addItem(1);
assertTrue("Testing addItem()", x.toJSON() == '[1,"text",1]');

x.addItemAt(1, obj1);
assertTrue("Testing addItemAt()", x.toJSON() == '[1,{label:"text",text:"a"},"text",1]');

var a = x.clone();
a.addItem(8);
assertNotEqual("Testing clone()", x.toJSON(), a.toJSON());
assertTrue("Testing containsItem()", x.containsItem(obj1));
x.merge('',a,[4,5]);
assertTrue("Testing merge()", x.containsItem(''), x.containsItem(4),x.containsItem(8));
x.compact();
assertFalse("Testing compact()", x.containsItem(''));
x.removeDuplicates(obj1);
var tmp = x.findItems("text");
assertEqual("Testing removeDuplicates()", tmp.length, 2);
assertTrue("Testing findItems('key')", tmp.length == 2, tmp[0].label == 'text', tmp[1] == 'text');
tmp = x.findItems("label","text");
assertTrue("Testing findItems('field','key')", tmp.length == 1, tmp[0].label == 'text')
assertEqual("Testing getItemAt()", x.getItemAt(1), "text");
assertEqual("Testing getItemIndex()", x.getItemIndex(obj1), 0);
x.removeItem(8);
assertEqual("Testing removeItem()", x.getItemIndex(8), -1);
x.removeItemAt(1);
assertEqual("Testing removeItemAt()", x.getItemIndex("text"), -1);
x.forEach(function(obj) {
    if (typeof obj !== 'object') {
        return obj * 10;
    }
});
assertNotEqual("Testing forEach()",x.getItemIndex(10), -1)
x.removeAll();
assertEqual("Testing removeAll()", x.length, 0);

delete(jclass.collections);
})();